{include file="public/header296"}
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding-top: 10px;">
      <div class="layui-form-item">
        <div class="layui-inline">
          <div class="layui-input-inline">
            <input type="text" name="start_date" id="start_date" placeholder="开始日期" autocomplete="off" class="layui-input" />
          </div>
          <div class="layui-input-inline">
            <input type="text" name="end_date" id="end_date" placeholder="截至日期" autocomplete="off" class="layui-input" />
          </div>
          <div class="layui-input-inline">
            <input type="text" name="keywords" placeholder="姓名/身份证" autocomplete="off" class="layui-input">
          </div>
          <div class="layui-input-inline">
            <select name="status">
              <option value="">状态</option>
              <option value="0">待审核</option>
              <option value="1">已审核</option>
              <option value="2">拒绝</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select name="type" id="type">
              <option value="1" selected>实名</option>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>
    <div class="layui-card-body">
      <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
      <script type="text/html" id="table-content-list">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="auth"><i class="layui-icon"></i>审核</a>
      </script>
    </div>
  </div>
</div>
<script>
  layui.use(['layer', 'table', 'laydate'], function () {
    var $ = layui.$
            , table = layui.table
            , laydate = layui.laydate
            , form = layui.form;
    laydate.render({
      elem: '#start_date'
      , trigger:'click'
    });
    laydate.render({
      elem: '#end_date'
      , trigger:'click'
    });
    var typeList = new Array();
    $("#type option").each(function(){
      var value = $(this).val();
      var text = $(this).text();
      if(value != ''){
        typeList[value] = text
      }
    })
    table.render({
      elem: '#LAY-app-content-list'
      , url: "{:url('audit/getUserAuditList')}"
      , where: { type:1}
      , request: {
        pageName: 'page',
        limitName: 'page_size'
      }
      , page: {
        layout: ['limit', 'count', 'prev', 'page', 'next']
        , first: '首页'
        , last: '尾页'
        , limit: 10
      }
      , toolbar:true
      , totalRow: true
      , cellMinWidth: 120
      , cols: [[
        {field: 'user_id', title: '用户id', align: 'center'}
        , {field: 'type', title: "认证类型", align:'center', templet: function (d) {
            return typeList[d.type] != undefined ? typeList[d.type] : ''
        }}
        , {field: 'nickname', title: '昵称', align: 'center'}
        ,{field: 'avatar', title: "头像", width: 45, align:'center', templet: function (d) {
            if (d.avatar != '') {
              str = '<div id="layer-photos-cover-'+ d.id +'" class="layer-photos-demo">';
              str +='<img layer-src="'+ d.avatar +'" width="40" src="' + d.avatar + '">';
              return str;
            } else{
              return '';
            }
          }}
        , {field: 'mobile', title: '手机', align: 'center'}
        , {field: 'status', title: '状态', align:'center', width:90, templet: function (d) {
            if (d.status == 1) {
              return '<button class="layui-btn layui-btn-xs layui-btn-primary ">已认证</button>'
            } else if(d.status == 2) {
              return '<button class="layui-btn layui-btn-xs layui-btn-danger ">拒绝</button>'
            } else{
              return '<button class="layui-btn layui-btn-xs ">审核中</button>'
            }
          }}
        , {field: 'create_time', title: '认证时间', align: 'center'}
        , {field: 'auth_time', title: '审核时间', align: 'center', templet: function (d) {
            if (d.status) {
              return d.auth_time;
            } else{
              return ''
            }
        }}
        , {title: '操作', align: 'center',width:90, fixed: 'right', toolbar: '#table-content-list'}
      ]]
      , text: {
        none: '暂无相关数据'
      }
      , done: function () {
        hoverOpenImage();
      },
    });
    form.on('submit(LAY-app-contlist-search)', function (data) {
      var field = data.field;
      table.reload('LAY-app-content-list', {
        page: {
          curr: 1
        }
        , where: field
      });
    });
    // 监听工具条
    table.on('tool(LAY-app-content-list)', function (obj) {
      var data = obj.data;
      if (obj.event === 'auth') {
        layer.open({
          type: 2
          , title: '认证审核'
          , content: "{:url('audit/auth')}?id=" + data.id + "&type=" + data.type
          , maxmin: true
          , area: ['85%', '90%']
          , btn: ['提交', '取消']
          , yes: function (index, layero) {
            var iframeWindow = window['layui-layer-iframe'+ index]
                    ,submit = layero.find('iframe').contents().find("#Lay-app-form-edit");

            iframeWindow.layui.form.on('submit(Lay-app-form-edit)', function(data){
              var field = data.field;
              if (typeof(field.status) == 'undefined') {
                return layer.msg("请选择审核状态", {icon:5});
              }
              if (field.status == 1) {
                $title = "通过";
              } else if(field.status == 2){
                $title = "拒绝";
              }
              if (field.status == 2 && field.remarks == "") {
                return layer.msg("请输入拒绝的原因", {icon:5});
              }
              layer.confirm("确定 "+ $title +" 吗？", {title: '审核操作'}, function () {
                    $.post("{:url('audit/auth')}", {id:field.id,type:field.type,status:field.status,remarks:field.remarks}, function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, {icon: 1});
                            layer.closeAll();
                            table.reload('LAY-app-content-list');
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    });
                });
            });
            submit.trigger('click');
          }
        });
      }
    });

    function hoverOpenImage(){
      var img_show = null;
      $('td img').hover(function(){
        var img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:275px;' />";
        img_show = layer.tips(img, this,{
          tips:[1, '#000']
          , area: ['300px', '290px']
          , maxWidth: 300
        });
      },function(){
        layer.close(img_show);
      });
    }

    var $ = layui.$, active = {

    };

    $('.layui-btn.layuiadmin-btn-list').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
</script>
{include file="public/footer" /}